﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace Cliente
{
    public class cliente
    {

        public static string enviar(String peticion)
        {
            TcpClient socketParaServidor;
            socketParaServidor = new TcpClient("localhost", 7892);
            Console.WriteLine("Cliente dice: " + peticion);

            NetworkStream networkStream = socketParaServidor.GetStream();

            StreamReader streamReader = new StreamReader(networkStream);

            StreamWriter streamWriter = new StreamWriter(networkStream);

            streamWriter.WriteLine(peticion);

            try
            {
                streamWriter.WriteLine(peticion);
                Console.WriteLine(peticion);
                streamWriter.Flush();
                peticion = (streamReader.ReadLine());
                Console.WriteLine(peticion);
                Console.ReadLine();
            }
            catch
            {
                Console.WriteLine("Exception reading from Server");
            }

            streamWriter.Flush();

            streamWriter.Close();
            networkStream.Close();


            return peticion;
        }


    }
}